﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Domain.PlcConnectPoolDomain;
using Zocono.WCS.Domain.ProcessModuleDomain;

namespace Zocono.WCS.Domain.EquipmentProcessDomain
{
    public class ProcessScService : IProcessScService
    {
        //private readonly IPlcConnectionPoolService _plcConnectionPoolService;
        private readonly IScMessageServiceFactory _scMessageServiceFactory;

        public ProcessScService(IScMessageServiceFactory scMessageServiceFactory)
        {
            _scMessageServiceFactory = scMessageServiceFactory;
        }

        /// <summary>
        /// 启动
        /// </summary>
        /// <param name="processModuleName"></param>
        /// <param name="scEquipmentDbObject"></param>
        /// <param name="puDoEquipmentDbObjects"></param>
        /// <returns></returns>
        public async Task ProcessAsync(string processModuleName, EquipmentDbObject scEquipmentDbObject, List<EquipmentDbObject> puDoEquipmentDbObjects)
        {
            //if (processModuleName.Contains("ZJN"))
            //{
            string objType = $"{processModuleName.Substring(processModuleName.Length - 3)}ScActionMessageService";
            var ZJNScActionMessageService = _scMessageServiceFactory.CreateScActionService(objType);
            await ZJNScActionMessageService.ProcessActionMessageAsync(scEquipmentDbObject, puDoEquipmentDbObjects);
            //}
            //else if (processModuleName.Contains("QT"))
            //{
            //    var QTScActionMessageService = _scMessageServiceFactory.CreateScActionService("QT");
            //    await QTScActionMessageService.ProcessActionMessageAsync(scEquipmentDbObject, puDoEquipmentDbObjects);
            //}

            //long plcId = 0;
            //var plcConn = _plcConnectionPoolService.S7GetWritePlcConnection(plcId);
            //byte[] bytes = new byte[1];
            //bool isSend = await plcConn.WriteDbAsync(0, 0, bytes);
        }


    }
}
